package com.bpc.cs.util;

import java.util.ArrayList;
import java.util.List;

import com.bpc.cs.dto.FactorChoiceDTO;
import com.bpc.cs.dto.FactorDTO;
import com.bpc.cs.dto.RuleDTO;
import com.bpc.cs.dto.SchemeDTO;
import com.bpc.cs.managed.dvo.FactorChoiceDVO;
import com.bpc.cs.managed.dvo.FactorDVO;
import com.bpc.cs.managed.dvo.RuleDVO;
import com.bpc.cs.managed.dvo.SchemeDVO;

/**
 * @author   phan_tp
 * @datetime Dec 12, 2012 : 5:18:44 PM
 */
public class Util {

	/**
	 * Convert List<SchemeDTO> to List<SchemeDVO>
	 * @param List<SchemeDTO> listSchemeDTO
	 * @return List<SchemeDVO>
	 */
	public static List<SchemeDVO> cvnSchemeDTO2DVO(List<SchemeDTO> listSchemeDTO) {
		List<SchemeDVO> listSchemeDVO = new ArrayList<SchemeDVO>();
		for (SchemeDTO schemeDTO : listSchemeDTO) {
			listSchemeDVO.add(new SchemeDVO(schemeDTO.getSchemeID(), schemeDTO.getSchemeName()));
		}
		return listSchemeDVO;
	}

	/**
	 * Convert SchemeDVO to SchemeDTO
	 * @param SchemeDVO schemeDVO
	 * @return SchemeDTO
	 */
	public static SchemeDTO cvnSchemeDVO2DTO(SchemeDVO schemeDVO) {
		SchemeDTO schemeDTO = new SchemeDTO();
		schemeDTO.setSchemeID(schemeDVO.getSchemeID());
		schemeDTO.setSchemeName(schemeDVO.getSchemeName());
		return schemeDTO;
	}

	/**
	 * Convert List<RuleDTO> to List<RuleDVO>
	 * @param List<RuleDTO> listRuleDTO
	 * @return List<RuleDVO>
	 */
	public static List<RuleDVO> cvnRuleDTO2DVO(List<RuleDTO> listRuleDTO) {
		List<RuleDVO> listRuleDVO = new ArrayList<RuleDVO>();
		for (RuleDTO ruleDTO : listRuleDTO) {
			RuleDVO ruleDVO = new RuleDVO();
			ruleDVO.setRuleID(ruleDTO.getRuleID());
			ruleDVO.setSchemeID(ruleDTO.getSchemeDTO().getSchemeID());
			ruleDVO.setFactorID(ruleDTO.getFactorDTO().getFactorID());
			ruleDVO.setFactorName(String.valueOf(ruleDTO.getFactorDTO().getFactorName()));
			ruleDVO.setWeight(ruleDTO.getWeight());
			listRuleDVO.add(ruleDVO);
		}
		return listRuleDVO;
	}

	/**
	 * Convert RuleDVO to RuleDTO
	 * @param RuleDVO ruleDVO
	 * @return RuleDTO
	 */
	public static RuleDTO cvnRuleDVO2DTO(RuleDVO ruleDVO) {
		RuleDTO ruleDTO = new RuleDTO();
		ruleDTO.setRuleID(ruleDVO.getRuleID());
		ruleDTO.setWeight(ruleDVO.getWeight());
		return ruleDTO;
	}

	/**
	 * Convert List<FactorChoiceDTO> to List<FactorChoiceDVO>
	 * @param List<FactorChoiceDVO> listFactorChoiceDTO
	 * @return List<FactorChoiceDTO>
	 */
	public static List<FactorChoiceDVO> cvnFactorChoiceDTO2DVO(List<FactorChoiceDTO> listFactorChoiceDTO) {
		List<FactorChoiceDVO> listFactorChoiceDVO = new ArrayList<FactorChoiceDVO>();
		for (FactorChoiceDTO factorChoiceDTO : listFactorChoiceDTO) {
			FactorChoiceDVO factorChoiceDVO = new FactorChoiceDVO();
			factorChoiceDVO.setFactorChoiceID(factorChoiceDTO.getFactorChoiceID());
			factorChoiceDVO.setRuleID(factorChoiceDTO.getRuleDTO().getRuleID());
			factorChoiceDVO.setFactorChoice(factorChoiceDTO.getFactorChoice());
			factorChoiceDVO.setScore(factorChoiceDTO.getScore());
			listFactorChoiceDVO.add(factorChoiceDVO);
		}
		return listFactorChoiceDVO;
	}

	/**
	 * Convert List<FactorDTO> to List<FactorDVO>
	 * @param List<FactorDVO> listFactorDTO
	 * @return List<FactorDTO>
	 */
	public static List<FactorDVO> cvnFactorDTO2DVO(List<FactorDTO> listFactorDTO) {
		List<FactorDVO> listFactorDVO = new ArrayList<FactorDVO>();
		for (FactorDTO factorDTO : listFactorDTO) {
			FactorDVO factorDVO = new FactorDVO();
			factorDVO.setFactorID(factorDTO.getFactorID());
			factorDVO.setFactorName(factorDTO.getFactorName());
			listFactorDVO.add(factorDVO);
		}
		return listFactorDVO;
	}

	/**
	 * Convert FactorDVO to FactorDTO
	 * @param FactorDVO factorDVO
	 * @return FactorDTO
	 */
	public static FactorDTO cvnFactorDVO2DTO(FactorDVO factorDVO) {
		FactorDTO factorDTO = new FactorDTO();
		factorDTO.setFactorID(factorDVO.getFactorID());
		factorDTO.setFactorName(factorDVO.getFactorName());
		return factorDTO;
	}

	/**
	 * Clone List SchemeDVO
	 * @param List<SchemeDVO> listSchemeDVO
	 * @return List<SchemeDVO>
	 */
	public static List<SchemeDVO> cloneListSchemeDVO(final List<SchemeDVO> listSchemeDVO) {
		List<SchemeDVO> lstRet = new ArrayList<SchemeDVO>();
		for (SchemeDVO schemeDVO : listSchemeDVO) {
			lstRet.add(cloneSchemeDVO(schemeDVO));
		}
		return lstRet;
	}

	/**
	 * Clone SchemeDVO object
	 * @param SchemeDVO schemeDVO
	 * @return SchemeDVO
	 */
	public static SchemeDVO cloneSchemeDVO(final SchemeDVO schemeDVO) {
		return new SchemeDVO(schemeDVO.getSchemeID(), schemeDVO.getSchemeName());
	}

	/**
	 * Clone List RuleDVO
	 * @param List<RuleDVO> listRuleDVO
	 * @return List<RuleDVO>
	 */
	public static List<RuleDVO> cloneListRuleDVO(final List<RuleDVO> listRuleDVO) {
		List<RuleDVO> lstRet = new ArrayList<RuleDVO>();
		for (RuleDVO ruleDVO : listRuleDVO) {
			lstRet.add(cloneRuleDVO(ruleDVO));
		}
		return lstRet;
	}

	/**
	 * Clone RuleDVO object
	 * @param RuleDVO ruleDVO
	 * @return RuleDVO
	 */
	public static RuleDVO cloneRuleDVO(final RuleDVO ruleDVO) {
		return new RuleDVO(ruleDVO.getRuleID(), ruleDVO.getSchemeID(), ruleDVO.getFactorID(), ruleDVO.getWeight());
	}
}
